package com.power.core
{
	import com.power.interfaces.IViewMediator;
	import com.power.mediators.FloorWindowViewMediator;
	import com.power.mediators.HouseWindowViewMediator;
	import com.power.mediators.RoomWindowViewMediator;
	import com.power.model.FloorVo;
	import com.power.model.RoomVo;
	
	import flash.display.Bitmap;
	import flash.events.Event;

	public class MainAppController
	{
		private var app:HongPro;
		
		private var mediators:Array = [];
		
		private var roomMediator:RoomWindowViewMediator = new RoomWindowViewMediator();
		
		private var floorMediator:FloorWindowViewMediator = new FloorWindowViewMediator();
		
		private var houserMediator:HouseWindowViewMediator = new HouseWindowViewMediator();
		
		private var dataSource:GetData;
		
		public function MainAppController()
		{
		}
		public function initMain(appview:HongPro):void
		{
			app = appview;
			houserMediator.initView(app.houseWindowView);
			//roomMediator.initView(app.roomWindowView);
			roomMediator.initRoomView(app.roomWindowView,houserMediator);
			//floorMediator.initView(app.floorWindowView,houserMediator);
			floorMediator.initFloorView(app.floorWindowView,houserMediator);
			mediators.push(houserMediator);
			mediators.push(roomMediator)
			mediators.push(floorMediator);
			hideAllViews();
			dataSource = GetData.GetInstance();
			setAllEventListener();
		}
		private function setAllEventListener():void
		{
			dataSource.addEventListener("AllDataIsReadly",startSetUpApp);
		}
		
		private function startSetUpApp(e:Event):void
		{
			trace("all datas are readly ! you can setup the app!");
			//initial floor window 
			var floorCategorys:Array = dataSource.getFloorCategorys();
			var floorvos:Vector.<FloorVo> = dataSource.getFloorData();
			
			floorMediator.initCategroys(floorCategorys);
			//floorMediator.getFloorVos(floorvos);
			houserMediator.setFloorImg(floorvos);
			floorMediator.initFloorTags(floorvos);
			
			//initial room window
			var roomCategorys:Array = dataSource.getRoomCategorys();
			var roomvos:Vector.<RoomVo> = dataSource.getRoomData();
			roomMediator.initCategroys(roomCategorys);
			houserMediator.setRoomImg(roomvos);
			roomMediator.initRoomTags(roomvos);
			//show all views
			showAllViews();
		}
		private function hideAllViews():void
		{
			for each(var view:IViewMediator in mediators)
			{
				view.hide();
			}
		}
		private function showAllViews():void
		{
			for each(var view:IViewMediator in mediators)
			{
				view.show();
			}
		}
	}
}